import time
import threading
lock = threading.Lock()
x=0
total =100000


def add_1():
    global x
    with lock:
        for i in range(total):
            x +=2


def add_2():
    global x
    with lock:
        for i in range(total):
            x +=3


def sub_1():
    global x
    with lock:
        for i in range(total):
            x -=4

def sub_2():
    global x
    with lock:
        for i in range(total):
            x -=1

t1=threading.Thread(target=add_1)
t2=threading.Thread(target=add_2)
t3=threading.Thread(target=sub_1)
t4=threading.Thread(target=sub_2)

t1.start()
t2.start()
t3.start()
t4.start()

t1.join()
t2.join()
t3.join()
t4.join()

print (x)